// 更新验证码
var $val_code_img = $("#val_code_img");
if ($val_code_img) {
    $val_code_img.attr('src', '/verification/img?r=4&t=' + Date.parse(new Date()));
    $val_code_img.click(function () {
        $val_code_img.attr('src', '/verification/img?r=4&t=' + Date.parse(new Date()));
    });
}


var $resetPasswordForm = $('#resetPasswordForm');

// initialization of form validation
$.HSCore.components.HSValidation.init('.js-validate', {
    rules: {
        confirmPassword: {
            equalTo: '#newPassword'
        }
    }
});

$resetPasswordForm.submit(function (e) {
    e.preventDefault();

    if (!$resetPasswordForm.valid()) {
        return;
    }

    abp.ui.setBusy(
        null,
        abp.ajax({
            contentType: abp.formex.contentTypeJson,
            url: $resetPasswordForm.attr('action'),
            data: JSON.stringify($resetPasswordForm.serializeJSON())
        }).done(function (data) {
            if (data) {
                abp.message.success("用户密码修改成功!")
                    .then(function () {
                        window.location.href = "/";
                    });
            }

        }).fail(function (error) {
            $val_code_img.click();
            abp.message.error(error.message);
        })
    );
})
